package utils

import (
	"fmt"
	"sync"
	"time"
)

var (
	lockGetUniqueKeys sync.Mutex
	lockGetUniqueKey  sync.Mutex
)

func GetUniqueKeys(n int) []string {
	if n > 1000*1000*1000 {
		panic("1秒内最多产生 1000 * 1000 * 1000 个UniqueKey")
	}
	result := []string{}
	lockGetUniqueKeys.Lock()
	for i := 0; i < n; i++ {
		time.Sleep(time.Nanosecond)
		time_int := time.Now().UnixNano()
		result = append(result, fmt.Sprintf("%d", time_int))
	}
	lockGetUniqueKeys.Unlock()
	return result
}

func GetUniqueKey() string {
	lockGetUniqueKey.Lock()
	time.Sleep(time.Nanosecond)
	time_int := time.Now().UnixNano()
	lockGetUniqueKey.Unlock()
	return fmt.Sprintf("%d", time_int)
}
